﻿using System;
using System.Text;

namespace GPS.GPSLanguage
{
    class DateToken
    {
        internal static void ParseLanguage(GPSData gpsData, System.Collections.Queue q)
        {
            String token = (string)q.Dequeue();

            DateTime dt = new DateTime();

            try
            {
                if (token.Length >= 6)
                {
                    int day, month, year;
                    day = int.Parse(token.Substring(0, 2));
                    month = int.Parse(token.Substring(2, 2));
                    year = int.Parse(token.Substring(4, 2));
                    //Assume if it sends us a year greater than 50 it's in the 1900s, else it's in the 2000s
                    if (year > 50)
                        year += 1900;
                    else
                        year += 2000;

                    dt = new DateTime(year, month, day);
                }
            }
            catch
            {
                
            }

            gpsData.SetDate(dt);

            switch (gpsData.MessageType)
            {
                case MessageType.GPRMC:
                    MagneticVariation.ParseLanguage(gpsData, q);
                    break;
                default:
                    throw new InvalidLanguageException("How did you get here?");
            }
        }
    }
}
